home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / gfx / misc / SafeClip.lha / SafeClip / SASC / demo.c < prev    next >
C/C++ Source or Header  |  1996-03-29  |  4KB  |  191 lines

  1. /*
  2.  * Name:        demo.c
  3.  * Description: Simple demonstration of safe clipping routines
  4.  * Author:      pak@star.sr.bham.ac.uk (Peter Knight)
  5.  *
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <graphics/gfxmacros.h>
  10. #include <intuition/intuition.h>
  11. #include <proto/intuition.h>
  12. #include <proto/dos.h>
  13. #include <proto/exec.h>
  14. #include <stdio.h>
  15. #include "safeclip.h"
  16.  
  17. /* Defines */
  18. #define WIDTH 320
  19. #define HEIGHT 200
  20. #define DEPTH 1
  21. #define XC (WIDTH>>1)
  22. #define YC (HEIGHT>>1)
  23. #define AREASIZE 1000
  24.  
  25. /* Variables */
  26. struct IntuitionBase *IntuitionBase = NULL;
  27. struct GfxBase *GfxBase = NULL;
  28. struct Window *win;
  29. struct Screen *scr;
  30. struct RastPort *rp;
  31. UWORD areaBuffer[AREASIZE];
  32.  
  33. /* Prototypes */
  34. VOID SafeDemo (VOID);
  35.  
  36. int
  37. main ()
  38. {
  39.  
  40.   if (IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 36L))
  41.     {
  42.  
  43.       if (GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 36L))
  44.     {
  45.  
  46.       if (scr = OpenScreenTags (NULL, 
  47.                     SA_Width, WIDTH,
  48.                     SA_Height, HEIGHT,
  49.                     SA_Depth, DEPTH,
  50.                     SA_Title, "Test of safe clipping routines...",
  51.                     TAG_END))
  52.         {
  53.  
  54.           if (win = OpenWindowTags (NULL, 
  55.                     WA_CustomScreen, scr,
  56.                     WA_Activate, TRUE,
  57.                     WA_Borderless, TRUE,
  58.                     WA_Backdrop, TRUE,
  59.                     TAG_END))
  60.         {  
  61.  
  62.           PLANEPTR planePtr;
  63.           if (planePtr = (PLANEPTR) AllocRaster (WIDTH, HEIGHT))
  64.             {
  65.               
  66.               /* Allocate standard area fill stuff */
  67.               struct AreaInfo areaInfo;
  68.               struct TmpRas tmpRas;
  69.               InitArea (&areaInfo, areaBuffer, (AREASIZE * 2) / 5);
  70.               InitTmpRas (&tmpRas, planePtr, RASSIZE (WIDTH, HEIGHT));
  71.               rp = win->RPort;
  72.               rp->AreaInfo = &areaInfo;
  73.               rp->TmpRas = &tmpRas;
  74.               
  75.               /* Mark boundary of clipping region */
  76.               Move (rp, XC - 75, YC - 75);
  77.               Draw (rp, XC - 75, YC + 75);
  78.               Draw (rp, XC + 75, YC + 75);
  79.               Draw (rp, XC + 75, YC - 75);
  80.               Draw (rp, XC - 75, YC - 75);
  81.               
  82.               /* Demonstrate clipping routines */
  83.               SafeDemo ();
  84.               
  85.               /* Free everything ... */
  86.               FreeRaster (planePtr, WIDTH, HEIGHT);
  87.               
  88.             }
  89.           else
  90.             fprintf (stderr, "Memory allocation failure\n");
  91.           
  92.           CloseWindow (win);
  93.           
  94.         }
  95.           else
  96.         fprintf (stderr, "Can't open window\n");
  97.           
  98.           CloseScreen (scr);      
  99.           
  100.         }
  101.       else
  102.         fprintf (stderr, "Can't open screen\n");
  103.  
  104.       CloseLibrary ((struct Library *) GfxBase);
  105.  
  106.     }
  107.       else
  108.     fprintf (stderr, "Requires graphics.library v36+\n");
  109.       
  110.       CloseLibrary ((struct Library *) IntuitionBase);
  111.  
  112.     }
  113.   else
  114.     fprintf (stderr, "Requires intuition.library v36+\n");
  115.  
  116. }
  117.  
  118. /*
  119.  * SafeDemo () - Simple demonstration of clipping routines.
  120.  */
  121. VOID
  122. SafeDemo (VOID)
  123. {
  124.  
  125.   /* Initialise clipping routines (up to 1000 vertices). */
  126.   if (!SafeInit (1000))
  127.     {
  128.       WORD r;
  129.  
  130.       /* Set drawing limits. */
  131.       SafeSetLimits (XC - 75 + 1, YC - 75 + 1,
  132.              XC + 75 - 1, YC + 75 - 1);
  133.  
  134.       /* Example of line clipping. */
  135.       SetWindowTitles (win, 0, "SafeMove()/SafeDraw() ...");
  136.       for (r = 0; r < 200; r+=4)
  137.     {
  138.       SafeMove (XC, YC - r);
  139.       SafeDraw (rp, XC + r, YC);
  140.       SafeDraw (rp, XC, YC + r);
  141.       SafeDraw (rp, XC - r, YC);
  142.       SafeDraw (rp, XC, YC - r);
  143.       Delay (10);
  144.     }
  145.       Delay (100);
  146.  
  147.       /* Example of filled polygon clipping. */
  148.       SetWindowTitles (win, 0, "SafeAreaDraw()/SafeAreaEnd() ...");
  149.       for (r = 0; r < 200; r+=4)
  150.     {
  151.       SafeAreaDraw (XC, YC - r);
  152.       SafeAreaDraw (XC + r, YC);
  153.       SafeAreaDraw (XC, YC + r);
  154.       SafeAreaDraw (XC - r, YC);
  155.       SafeAreaEnd (rp);
  156.       Delay (10);
  157.     }
  158.       Delay (100);
  159.  
  160.       /* Clearing the clipping region. */
  161.       SetWindowTitles (win, 0, "SafeSetRast() ...");
  162.       SafeSetRast (rp, 0);
  163.       Delay (100);
  164.  
  165.       /* Example of safe blitting. */
  166.       SetWindowTitles (win, 0, "SafeBltBitMapRastport() ...");
  167.       DrawCircle (rp, 30, 30, 10);
  168.       for (r = 0; r < 200; r++)
  169.     {
  170.       LONG x = XC + RangeRand (200) - 100;
  171.       LONG y = YC + RangeRand (200) - 100;
  172.       SafeBltBitMapRastPort (rp->BitMap, 20, 20,
  173.                  rp, x, y, 21, 21, 0x60);
  174.       Delay (2);
  175.     }
  176.       Delay (100);
  177.  
  178.       /* Setting the clipping region to a certain pen colour. */
  179.       SetWindowTitles (win, 0, "SafeRectFill() ...");
  180.       SafeRectFill (rp, 0, 0, WIDTH, HEIGHT);
  181.       Delay (100);
  182.  
  183.       /* Free any resources. */
  184.       SafeClose ();
  185.  
  186.     }
  187.  
  188. }
  189.  
  190.  
  191.